﻿using Godot;
using System;
using System.Collections.Generic;
using System.Linq;

public class TargetsData : ITargetsData
{
    private List<UIElement> _newTargets;
    private List<UIElement> _oldTargets;
    public IReadOnlyList<UIElement> Targets => _newTargets;
    public bool HasTarget => _newTargets.Count > 0;
    public event EventHandler<SelectDataEventArgs> TargetsChanged;
    public void SetTargets(IEnumerable<UIElement> targets)
    {
        if (_newTargets.Count == targets.Count() && _newTargets.All(targets.Contains))
            return;
        var now = _oldTargets;
        _oldTargets = _newTargets;
        now.Clear();
        now.AddRange(targets);
        TargetsChanged?.Invoke(this, new SelectDataEventArgs(_newTargets, _oldTargets));
    }
}
